<? header("content-Type: text/html; charset=UTF-8");
date_default_timezone_set("PRC");
?>

<?php

	//包含数据库链接文件：
	include('conn.php');  

//	var_dump($_POST);
//exit();

	$userid 				= $_POST['userid'];							//ԃ»§ID
	$typeid					= $_POST['typeid'];
	$order_no 			= time().rand(100,1000);
	//¶©µ¥ºÍ
	$deposit_name 	= iconv("utf-8","gb2312//IGNORE", $_POST['nickName']);				//»䀮ɋѕĻ
	$deposit_amount = $_POST['payMoney'];			//½𷬍
	$deposit_date 	= $_POST['time_input'];				//»䀮ɕǚ
//	$deposit_bank 	= $_POST['deposit_bank'];				//»䀮Ӹѐ index
//	$deposit_way 		= $_POST['deposit_way'];				//»䀮·½ʽ	index
//	$deposit_bank 	= iconv("utf-8","gb2312//IGNORE", $_POST['sel_bank_name']);				//»䀮Ӹѐ
//	$deposit_way 		= iconv("utf-8","gb2312//IGNORE", $_POST['sel_deposit_way']);				//»䀮·½ʽ
	$deposit_remark = iconv("utf-8","gb2312//IGNORE", $_POST['deposit_remark']);			//»䀮±¸ע

	if(strlen($deposit_name) <2 || strlen($deposit_name) > 30)
	{
		if($typeid == "1")
			exit('微信昵称不能为空！');
		if($typeid == "2")
			exit('支付宝昵称不能为空！');
	}
	
	if(strlen($userid) < 2 || strlen($userid) > 12)
		exit('userid 错误！');
		
	$order_time = $deposit_date;
	//echo $order_time ;
	$attach_info = $deposit_name .'|'. $deposit_amount .'|'. $order_time .'|'. $deposit_remark;
	
	$time_now		= date("Y-m-d H:i:s",time());

	//check the userid
	$sql="select * from t_user where t_id=$userid";
	$query=sqlsrv_query($conn,$sql);
	$result=sqlsrv_fetch_array($query,SQLSRV_FETCH_NUMERIC);
	if(empty($result)){
		echo "USERID 不存在";
		exit;
	}
	
	//check the ordernumber
	$sql="select * from t_chongzhi_log where order_no='$order_no' and t_user_id=$userid";
	$query=sqlsrv_query($conn,$sql);
	$result=sqlsrv_fetch_array($query,SQLSRV_FETCH_NUMERIC);
	if(empty($result)){
		$deposit_remark = iconv("utf-8","gb2312//IGNORE","首次|") . $deposit_remark;
	}
	else
		$deposit_remark= iconv("utf-8","gb2312//IGNORE","修改|"). $deposit_remark;

	if($typeid == "1")
		$content = iconv("utf-8","gb2312//IGNORE","微信转账");
	else if($typeid == "2")
		$content = iconv("utf-8","gb2312//IGNORE","支付宝转账");
	else
		$content = iconv("utf-8","gb2312//IGNORE","转账");
	
	$sql="insert into t_chongzhi_log (t_user_id,t_jine,t_time,t_state,t_pingtai,t_tishi,order_no,comments,attach) 
						values ($userid,$deposit_amount,'$time_now',0,'$content',0,'$order_no','$deposit_remark','$attach_info')";
//		echo $sql;
	$query=sqlsrv_query($conn,$sql);
		//print_r(sqlsrv_errors());
		//exit;
//	echo "success";
//	echo iconv("gb2312","utf-8//IGNORE",$attach_info);
	
	
?>